package pers.mobian.springeighth;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.beans.PropertyDescriptor;

/**
 * @Date 2021/7/25 14:05
 * @Created mobian
 * @Description
 */
@Component
@Repository
public class Student implements InitializingBean, BeanNameAware, BeanClassLoaderAware, BeanFactoryAware {

	@Value("mobian")
	private String name;

	static {
		System.out.println("232");
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	//	@Override
//	public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
//		System.out.println(beanName);
//		System.out.println("1、实例化前");
//		return null;
//	}

	public Student() {
		System.out.println("2、实例化zhong：" + name);
	}


	//
//	@Override
//	public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
//		System.out.println("3、实例化后");
//		return false;
//	}


	@Override
	public void setBeanName(String name) {
		System.out.println("4.1、初始化前前，设置beanName");
		System.out.println(name);
		System.out.println(this.name);
	}

	@Override
	public void setBeanClassLoader(ClassLoader classLoader) {
		System.out.println("4.2、初始化前前，设置classLoader");
		System.out.println(classLoader);
	}

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		System.out.println("4.3、初始化前前，设置beanFactory");
		System.out.println(beanFactory);
	}


//	@Override
//	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
//		System.out.println("5、初始化前");
//		return null;
//	}

	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("6、初始化zhong：" + this.name);
	}
//
//	@Override
//	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
//		System.out.println("7、初始化后");
//		return null;
//	}


}
